package com.yeqiangwei.commons.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.apache.commons.beanutils.Converter;

public class BeanUtilsDateConverter implements Converter {
	
	private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	@Override
	public Object convert(Class arg0, Object arg1) {
		String p = (String) arg1;
		if (p == null || p.trim().length() == 0) {
			return null;
		}
		if (arg0.equals(java.util.Date.class)) {
			try {
				return SDF.parse(p.trim());
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

}
